package processor;


import parser.MySimpleNode;
import parser.XQueryParser;


/*
  This program parses XQuery statements and prints the resulting parse tree.
  Calc programs should be entered on standard input.
  The resulting parse tree is printed on standard output.
*/
class XQueryDumpTree {

public static void main(String args[]) {
  
    /*
      Create a parser which reads from standard input
    */
//	  FileInputStream fis = null;
//	  try
//	{
//		fis = new FileInputStream("bar.txt");
//	} catch (FileNotFoundException e1)
//	{
//		e1.printStackTrace();
//	}
	  XQueryParser parser = new XQueryParser(System.in);
	  //XQueryParser parser = new XQueryParser(fis);
	  
    try {
    
      /*
        Start parsing from the nonterminal "Start".
      */
    	MySimpleNode parseTree = (MySimpleNode) parser.Start();
    	//parseTree.process();


//      @SuppressWarnings("unchecked")
 //     List<Node> foobar = (List<Node>) parseTree.process();
  //    System.out.println(foobar);
    	
      /*
        If parsing completed without exceptions, print the resulting
        parse tree on standard output.
      */
      parseTree.dump("");
      
      
    } catch (Exception e) {
    
      /*
        An exception occurred during parsing.
        Print the error message on standard output.
      */
      System.out.println("---------------------------");
      System.out.println("Sorry, couldn't parse that.");
      System.out.println(e.getMessage());
      System.out.println("---------------------------");
      
      /*
        Print the call stack 
      */
      System.out.println("Call stack:");
      e.printStackTrace();
      System.out.println("---------------------------");
    }
  }
  
}

